package com.wwh.spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author Albert
 * @date 2024/8/27-21:36
 * @describe
 */
@Component
@Aspect
public class CalAspect {
    //给Cal配置前置、返回、异常、后置通知
    @Before(value = "execution(public float com.wwh.spring.aop.Cal.*(float, float))")
    public void showBeginLog(JoinPoint joinPoint){
        System.out.println("日志-执行前-切面类-showBeginLog-方法名-" + joinPoint.getSignature().getName() + "-参数" + Arrays.asList(joinPoint.getArgs()));//前置通知
    }

    @AfterReturning(value = "execution(public float com.wwh.spring.aop.Cal.*(float, float))", returning = "res")
    public void showSuccessEndLog(JoinPoint joinPoint, Object res){
        System.out.println("日志-执行后-切面类-showSuccessEndLog-方法名-" + joinPoint.getSignature().getName() + " 返回结果=" + res);//返回通知
    }

    @AfterThrowing(value = "execution(public float com.wwh.spring.aop.Cal.*(float, float))", throwing = "throwable")
    public void showExceptionLog(JoinPoint joinPoint, Exception throwable){
        System.out.println("日志-出异常-切面类-showExceptionLog-方法名-" + joinPoint.getSignature().getName() + " 异常信息=" + throwable);//返回通知
    }

    @After(value = "execution(public float com.wwh.spring.aop.Cal.*(float, float))")
    public void showFinallyEndLog(JoinPoint joinPoint){
        System.out.println("日志-方法后-切面类-showFinallyEndLog-方法名-" + joinPoint.getSignature().getName());//返回通知
    }
}
